home *** CD-ROM | disk | FTP | other *** search
/ Freelog 46 / Freelog046.iso / Alu / Celestia / Win32LoresTex / celestia-lores-win32-1.3.0.exe / {app} / shaders / specular.vp < prev   
Text File  |  2002-11-19  |  2KB  |  76 lines

  1. !!VP1.0
  2.  
  3. # Compute specular and diffuse light from a single source
  4.  
  5. # c[0]..c[3] contains the concatenation of the modelview and projection matrices.
  6. # c[4]..c[7] contains the inverse transpose of the modelview
  7. # c[15] contains the eye position in object space
  8. # c[16] contains the light direction in object space
  9. # c[17] contains H, the normalized sum of the eye and light direction
  10. # c[20] contains the object color * light color
  11. # c[32] contains the ambient light color
  12. # c[33] contains the haze color
  13. # c[34] contains the specular color * light color
  14. # c[40] contains (0, 1, 0, specPower)
  15. # v[OPOS] contains the per-vertex position
  16. # v[NRML] contains the per-vertex normal
  17. # v[TEX0] contains the per-vertex texture coordinate 0
  18. # o[HPOS] output register for homogeneous position
  19. # o[TEX0] output register for texture coordinate 0
  20. # o[COL0] output register for primary color
  21. # R0...R11 temporary registers
  22.  
  23. # Transform the vertex by the modelview matrix
  24. DP4   R1.x, c[0], v[OPOS];
  25. DP4   R1.y, c[1], v[OPOS];
  26. DP4   R1.z, c[2], v[OPOS];
  27. DP4   R1.w, c[3], v[OPOS];
  28.  
  29. # Compute the diffuse light component
  30. DP3   R2, v[NRML], c[16];
  31. # Clamp the diffuse component to zero
  32. MAX   R2.x, R2, c[40].xxxx;
  33.  
  34. # Get the vector from the eye to the vertex
  35. ADD   R4, c[15], -v[OPOS];
  36.  
  37. # Normalize it
  38. DP3   R0.w, R4, R4;
  39. RSQ   R0.w, R0.w;
  40. MUL   R4.xyz, R4, R0.w;
  41.  
  42. # Haze
  43. DP3   R2.y, v[NRML], R4;
  44. ADD   R2.y, c[40].y, -R2.y;
  45. MUL   o[FOGC].x, R2.x, R2.y;
  46.  
  47. # Compute the half angle vector for specular lighting
  48. ADD   R7, R4, c[16];
  49. DP3   R0.w, R7, R7;
  50. RSQ   R0.w, R0.w;
  51. MUL   R7, R0.w, R7;
  52.  
  53. # Calculate the specular reflection
  54. MOV   R6.x, R2.x;
  55. # DP3   R6.y, c[17], v[NRML];
  56. DP3   R6.y, R7, v[NRML];
  57. MAX   R6.y, R6, c[40].x;
  58. MOV   R6.w, c[40].w;
  59.  
  60. # Output the texture
  61. MOV   o[TEX0], v[TEX0];
  62. MOV   o[TEX1], v[TEX1];
  63.  
  64. # Output the primary color
  65. MOV   R0, c[32];
  66. MAD   o[COL0], c[20], R2.xxxx, R0;
  67.  
  68. # Compute and output the secondary color
  69. LIT   R0, R6;
  70. MUL   o[COL1], c[34], R0.zzzz;
  71. # Output the vertex
  72. MOV   o[HPOS], R1;
  73.  
  74. END
  75.  
  76.